//给服务器发送一个数据，告诉服务器要发送1024字节的数据，但是实际发送的数据不足1024，查看服务器处理结果
//1. 如果数据只发送一次，服务器将得不到完整请求，就不会进行业务处理，客户端也就得不到响应，最终超时关闭连接
//2. 连着给服务器发送多次 小请求，服务器会将后边的请求当做前边请求的正文进行处理，而后边处理的时候有可能就会因为处理错误而关闭连接

#include "../include/server.hpp"
#include <unistd.h>
#include <cassert>
#include <cstdlib>
#include <cstring>

int main()
{
    Muduo::Socket cli_sock;
    cli_sock.CreateClientSocket(8888, "127.0.0.1");
    std::string req = "GET /hello HTTP/1.1\r\nConnection: close\r\nContent-Length: 100\r\n\r\nyou can see!";
    while(1) {
        int ret = cli_sock.Send((void*)req.c_str(), req.size());
        cli_sock.Send((void*)req.c_str(), req.size());
        cli_sock.Send((void*)req.c_str(), req.size());
        cli_sock.Send((void*)req.c_str(), req.size());
        cli_sock.Send((void*)req.c_str(), req.size());
        cli_sock.Send((void*)req.c_str(), req.size());
        cli_sock.Send((void*)req.c_str(), req.size());
        cli_sock.Send((void*)req.c_str(), req.size());
        cli_sock.Send((void*)req.c_str(), req.size());
        if(ret < 0){
            perror("出错了\n");
            break;
        }
        char buf[1024] = {0};
        assert(cli_sock.Recv(buf, 1023));
        LOGDEBUG("[%s]", buf);
        sleep(2);
    }
    cli_sock.Close();
    return 0;
}